import torch.nn as nn
from torch.utils.tensorboard import SummaryWriter
import torch
from PIL import Image
from torchvision import transforms

# input = torch.tensor([
#     [1, 2, 0, 3, 1],
#     [0, 1, 2, 3, 1],
#     [1, 2, 1, 0, 0],
#     [5, 2, 3, 1, 1],
#     [2, 1, 0, 1, 1]
# ], dtype=torch.float32)
# input = torch.reshape(input, (-1, 1, 5, 5))
# print(input.shape)

class MyMaxPool(nn.Module):
    def __init__(self):
        super().__init__()
        self.maxpool = nn.MaxPool2d(kernel_size=16, ceil_mode=True)

    def forward(self, x):
        return self.maxpool(x)

mpool = MyMaxPool()
# output = mpool(input)
# print(output)

original_img = Image.open("./dataset/mashu.jpg")
tensor_img = transforms.ToTensor()(original_img)
reshape_tensor_img = torch.reshape(tensor_img, (-1, 3, 1024, 1024))
output_img = mpool(reshape_tensor_img)

writer = SummaryWriter("./logs")
writer.add_image("原图片-麻薯", tensor_img)
writer.add_images("最大池化后-麻薯", output_img)
writer.close()
